package controller;



import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import service.LogService;
import service.UserService;

    @Controller
    public class User {
	// 登录
	@RequestMapping(value = "/login.action", method = RequestMethod.POST)
	@ResponseBody
	public String login(
			@RequestParam(value = "account", defaultValue = "") String account,
			@RequestParam(value = "password", defaultValue = "") String password,
			HttpServletResponse response) {
	UserService service = new UserService();
	LogService service2= new LogService();
	pojo.User  result = service.queryone(account, password);
	Cookie cooki = new Cookie("user", result.getId());
	response.addCookie(cooki);
	//System.out.println(result);
	service2.insert(result.getId(),"0", "登陆");
    if ("0".equals(result.getCounter())) {return "ERR";}
	return "OK";
    }

} 
